package com.cusc.lib_api.http;

import android.text.TextUtils;

import com.tencent.mmkv.MMKV;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 作者: wangfei
 * 创建时期: 2020/4/9.
 * 包名: com.cusc.lib_api.http
 * 类名: OSAndroidMvvm
 */
public class OkHeaderInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        Request.Builder builder = request.newBuilder();
        String token = MMKV.defaultMMKV().decodeString("Token","");
        if (!TextUtils.isEmpty(token)){
            builder.addHeader("token", token);
        }
        String curInPlatformModuleId = MMKV.defaultMMKV().decodeString("curInPlatformModuleId","");
        if (!TextUtils.isEmpty("curInPlatformModuleId")){
            builder.addHeader("curInPlatformModuleId", curInPlatformModuleId);
        }
        request = builder.build();
        return chain.proceed(request);
    }
}
